<template>
  <div>
    <a-table :columns="columns" :data-source="data" :pagination="pagination" bordered size="small">
      <template slot="group" slot-scope="group">
        <a :href="group.url" target="_blank">{{ group.name }}</a>
      </template>
      <template slot="title">豆瓣读书 Top 250</template>
      <template slot="footer">"豆瓣根据每本书读过的人数以及该书所得的评价等综合数据，通过算法分析产生了豆瓣读书 Top 250" ( update：2020.11.04 )</template>
    </a-table>
  </div>
</template>

<script>
import dataConfig from './config';
// import ruankaoConfig from './ruankao';

const list = dataConfig.pyBookTop250.map((item, index) => {
  return {
    ...item,
    key: index + 1,
    group: {
      name: item.name,
      url: item.url,
    },
  };
});

const columns = [
  {
    title: '序号',
    dataIndex: 'key',
  },
  {
    title: '书名',
    dataIndex: 'group',
    scopedSlots: { customRender: 'group' },
  },
  {
    title: '作者',
    dataIndex: 'author',
  },
  {
    title: '日期',
    dataIndex: 'date',
  },
  {
    title: '评分',
    dataIndex: 'rate',
  },
  {
    title: '概述',
    dataIndex: 'comment',
  },
];

// 软考视频课程
// const course = ruankaoConfig.course.chapters || [];
// const newCourse = {};
// const allTime = [];
// for (let i = 0; i < course.length; i += 1) {
//   const item = course[i];
//   newCourse[`${i + 1}--${item.title}`] = [];
//   for (let j = 0; j < item.sections.length; j += 1) {
//     const ite = item.sections[j];
//     newCourse[`${i + 1}--${item.title}`].push({
//       title: ite.title,
//       lessonLengthStr: ite.lessonLengthStr,
//     });
//     const temp = ite.lessonLengthStr.split(':');
//     let seconds = 0;
//     if (temp.length === 2) {
//       seconds = 60*Number(temp[0]) + Number(temp[1]);
//     } else if (temp.length === 3) {
//       seconds = 3600*Number(temp[0]) + 60*Number(temp[1]) + Number(temp[2])
//     }
//     allTime.push({
//       name: ite.title,
//       time: ite.lessonLengthStr,
//       seconds: seconds,
//     });
//   }
// }
// console.log(newCourse);
// console.log(allTime);
// console.log(JSON.stringify(allTime));

export default {
  data() {
    return {
      data: list,
      columns,
      pagination: {
        pageSize: 25,
      },
    };
  },
};
</script>

<style lang="less" scoped>
.book-img {
  height: 100px;
}
</style>
